#include "Entity/IEntity.hpp"
#include "Graphics/ISprite.hpp"
#include "Physics/PhysWorld.hpp"
#include "Utility/PropertyParser.hpp"
#include "Utility/Singleton.hpp"

#include "Box2D/Dynamics/b2World.h"

#include "SFML/Graphics/RenderWindow.hpp"

#include <iostream>

int main( int argc, char *argv[] )
{
	sf::RenderWindow *renderWnd = Utility::Singleton< sf::RenderWindow >::Get();
	renderWnd->Create( sf::VideoMode( 1024, 768 ), "Caffeine" );
	renderWnd->SetFramerateLimit( 60 );
	sf::Event wndEvent;

	Physics::PhysWorld *physWorld = Utility::Singleton< Physics::PhysWorld >::Get();
	physWorld->SetGravity( Math::Vectorf( 0.0f, -9.81f ) );

	Utility::PropertyParser parser( "../levels/1.txt" );

	while ( renderWnd->IsOpened() )
	{
		renderWnd->GetEvent( wndEvent );

		if ( wndEvent.Type == sf::Event::Closed )
		{
			renderWnd->Close();
			break;
		}

		Entity::IEntity::ThinkAll( renderWnd->GetFrameTime() );
		physWorld->Step( renderWnd->GetFrameTime(), 10 );

		renderWnd->Clear( sf::Color( 0, 128, 255 ) );
			Graphics::ISprite::DrawAll();
		renderWnd->Display();
	}

	return 0;
}